﻿<%@ WebHandler Language="C#" Class="ZxglAjax" %>

using System;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Web.Script.Serialization;
public class ZxglAjax : MyAjaxBase
{


    ArrayList jhArrayMySelf = null;
    string strBallsCount = "";
    int lhzFlag = 0;//当lhzFlag 用于判断连号组数
    string strWs = "";//尾数


    public override void ProcessRequest(HttpContext context)
    {
        try
        {
            //Init();
            string json = "";
            string QS = "0";
            switch (operType)
            {
                case "newarrayByTogether":
                    newarrayByTogether();
                    break;
                case "historyCompare":
                    QS = context.Request.Params["QS"];
                    HttpContext.Current.Response.Write(fnObjectToJSON(historyCompare(QS)));
                    break;
                default:
                    json = context.Request.Params["filters"];
                    CreateBall(json);
                    break;
            }
        }
        catch
        {
            alertmessage("操作异常");
        }

    }

    public List<Model.LotteryAnnouncement> historyCompare(string QS)
    {
        List<Model.LotteryAnnouncement> lstDBallModel = BLL.LotteryAnnouncement.GetListOrderBy(" id desc ", " LotteryType=1 ", " top " + QS, " [LotteryQS],[LotteryNO], [oneMoney],[twoMoney],[threeMoney],[fourMoney],[fiveMoney],[sixMoney] ");
        List<Model.LotteryAnnouncement> lstOneModel = new List<Model.LotteryAnnouncement>();
        ArrayList LotteryArrayList = BLL.ArrayListClass.GetArrayList(); //过滤后，投注号码串
        //List<Model.LotteryChipped> lstDoubleMod = new List<Model.LotteryChipped>();//过滤后的投注号码
        List<Model.DoubleBall> lstDoubleMod = new List<Model.DoubleBall>();

        string[] strball = (string[])LotteryArrayList.ToArray(typeof(string));
        for (int i = 0; i < strball.Length; i++)
        {
            Model.DoubleBall modelLottery = new Model.DoubleBall();
            strball[i] = strball[i].Substring(0, strball[i].LastIndexOf(',')).Replace(",", "*") + strball[i].Substring(strball[i].LastIndexOf(',')).Replace(",", "+");
            modelLottery.Larr = strball[i].ToString();
            lstDoubleMod.Add(modelLottery);
        }

        //所有的球分组
        string[] arrAllBall;
        //所有的红球
        string[] allRed;
        string allBlue;
        //所有中奖号码的变量
        string[] zAllBall;
        string[] zAllRedBall;
        //用来判断是否是当前行
        int CurrentLine = 0;
        //用来记录每条数据 红球 相同的数量
        int[] RedSameNum = new int[lstDBallModel.Count];
        bool CCCC = true;

        for (int i = 0; i < lstDoubleMod.Count; i++)
        {
            CCCC = true;
            arrAllBall = lstDoubleMod[i].Larr.Split('+');//分隔红球与蓝球
            allRed = arrAllBall[0].Split('*');//将红球分隔
            allBlue = arrAllBall[1];//蓝球
            for (int c = 0; c < allRed.Length; c++)
            {

                //所有中奖的号码 中奖号码相关变量命名 前都有 z
                for (int j = 0; j < lstDBallModel.Count; j++)
                {
                    zAllBall = lstDBallModel[j].LotteryNo.Split('+');
                    zAllRedBall = zAllBall[0].Split(',');
                    for (int d = 0; d < zAllRedBall.Length; d++)
                    {
                        if (allRed[c] == zAllRedBall[d])
                        {
                            //如果相等证明是当前行
                            if (CurrentLine == i)
                            {
                                RedSameNum[j] = RedSameNum[j] + 1;
                            }
                            else
                            {
                                for (int a = 0; a < lstDBallModel.Count; a++)
                                {
                                    RedSameNum[a] = 0;
                                }
                                RedSameNum[j] = 1;
                                CurrentLine = i;
                            }

                            break;
                        }

                    }



                }

            }
            for (int j = 0; j < lstDBallModel.Count; j++)
            {
                zAllBall = lstDBallModel[j].LotteryNo.Split('+');
                zAllRedBall = zAllBall[0].Split(',');

                //红球相等数量6+1一等奖
                if (allBlue == zAllBall[1] && RedSameNum[j] == 6)
                {
                    Model.LotteryAnnouncement ModOne = new Model.LotteryAnnouncement();

                    if (CCCC != false)
                    {
                        ModOne.id = 1;
                        ModOne.LotteryQS = lstDBallModel[j].LotteryQS;
                        ModOne.LotteryNo = lstDBallModel[j].LotteryNo;
                        ModOne.oneMoney = lstDBallModel[j].oneMoney;
                        lstOneModel.Add(ModOne);
                    }

                }
                else if (allBlue != zAllBall[1] && RedSameNum[j] == 6)//6+0 二等奖
                {
                    Model.LotteryAnnouncement ModTwo = new Model.LotteryAnnouncement();

                    if (CCCC != false)
                    {
                        ModTwo.id = 2;
                        ModTwo.LotteryQS = lstDBallModel[j].LotteryQS;
                        ModTwo.LotteryNo = lstDBallModel[j].LotteryNo;
                        ModTwo.twoMoney = lstDBallModel[j].twoMoney;
                        lstOneModel.Add(ModTwo);
                    }

                }
                else if (allBlue == zAllBall[1] && RedSameNum[j] == 5)//5+1三等奖
                {
                    Model.LotteryAnnouncement ModThree = new Model.LotteryAnnouncement();

                    if (CCCC != false)
                    {
                        ModThree.id = 3;
                        ModThree.LotteryQS = lstDBallModel[j].LotteryQS;
                        ModThree.LotteryNo = lstDBallModel[j].LotteryNo;
                        ModThree.threeMoney = lstDBallModel[j].threeMoney;
                        lstOneModel.Add(ModThree);

                    }
                }
                else if (allBlue == zAllBall[1] && RedSameNum[j] == 4)//4+1或5四等奖
                {
                    Model.LotteryAnnouncement ModFour = new Model.LotteryAnnouncement();

                    if (CCCC != false)
                    {
                        ModFour.id = 4;
                        ModFour.LotteryQS = lstDBallModel[j].LotteryQS;
                        ModFour.LotteryNo = lstDBallModel[j].LotteryNo;
                        ModFour.fourMoney = lstDBallModel[j].fourMoney;
                        lstOneModel.Add(ModFour);

                    }
                }
                else if (allBlue != zAllBall[1] && RedSameNum[j] == 5)//4+1或5四等奖
                {
                    Model.LotteryAnnouncement ModFour = new Model.LotteryAnnouncement();

                    if (CCCC != false)
                    {
                        ModFour.id = 4;
                        ModFour.LotteryQS = lstDBallModel[j].LotteryQS;
                        ModFour.LotteryNo = lstDBallModel[j].LotteryNo;
                        ModFour.fourMoney = lstDBallModel[j].fourMoney;
                        lstOneModel.Add(ModFour);
                    }
                }
                else if (allBlue == zAllBall[1] && RedSameNum[j] == 3)//3+1或4五等奖
                {
                    Model.LotteryAnnouncement ModFive = new Model.LotteryAnnouncement();

                    if (CCCC != false)
                    {
                        ModFive.id = 5;
                        ModFive.LotteryQS = lstDBallModel[j].LotteryQS;
                        ModFive.LotteryNo = lstDBallModel[j].LotteryNo;
                        ModFive.fiveMoney = lstDBallModel[j].fiveMoney;
                        lstOneModel.Add(ModFive);
                    }
                }
                else if (allBlue != zAllBall[1] && RedSameNum[j] == 4)//3+1或4五等奖
                {
                    Model.LotteryAnnouncement ModFive = new Model.LotteryAnnouncement();

                    if (CCCC != false)
                    {
                        ModFive.id = 5;
                        ModFive.LotteryQS = lstDBallModel[j].LotteryQS;
                        ModFive.LotteryNo = lstDBallModel[j].LotteryNo;
                        ModFive.fiveMoney = lstDBallModel[j].fiveMoney;
                        lstOneModel.Add(ModFive);
                    }
                }
                else if (allBlue == zAllBall[1] && RedSameNum[j] == 2)//2+1，1+1或1六等奖
                {
                    Model.LotteryAnnouncement ModSix = new Model.LotteryAnnouncement();

                    if (CCCC != false)
                    {
                        ModSix.id = 6;
                        ModSix.LotteryQS = lstDBallModel[j].LotteryQS;
                        ModSix.LotteryNo = lstDBallModel[j].LotteryNo;
                        ModSix.sixMoney = lstDBallModel[j].sixMoney;
                        lstOneModel.Add(ModSix);
                    }
                }
                else if (allBlue == zAllBall[1] && RedSameNum[j] == 1)//2+1，1+1或1六等奖
                {
                    Model.LotteryAnnouncement ModSix = new Model.LotteryAnnouncement();

                    if (CCCC != false)
                    {
                        ModSix.id = 6;
                        ModSix.LotteryQS = lstDBallModel[j].LotteryQS;
                        ModSix.LotteryNo = lstDBallModel[j].LotteryNo;
                        ModSix.sixMoney = lstDBallModel[j].sixMoney;
                        lstOneModel.Add(ModSix);
                    }
                }
                else if (allBlue == zAllBall[1] && RedSameNum[j] == 0)//2+1，1+1或1六等奖
                {
                    Model.LotteryAnnouncement ModSix = new Model.LotteryAnnouncement();

                    if (CCCC != false)
                    {
                        ModSix.id = 6;
                        ModSix.LotteryQS = lstDBallModel[j].LotteryQS;
                        ModSix.LotteryNo = lstDBallModel[j].LotteryNo;
                        ModSix.sixMoney = lstDBallModel[j].sixMoney;
                        lstOneModel.Add(ModSix);
                    }
                }
            }

        }
        return lstOneModel;
    }

    /// <summary>
    /// list 序列化 调用方法fnObjectToJSON(lstSix)
    ///  List<Model.LotteryAnnouncement> lstSix = new List<Model.LotteryAnnouncement>();
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="_t"></param>
    /// <returns></returns>
    public string fnObjectToJSON<T>(T _t)
    {
        JavaScriptSerializer oJavaSeria = new JavaScriptSerializer();

        try
        {
            return oJavaSeria.Serialize(_t);
        }
        catch (Exception ex)
        {

            throw new Exception("JSONHelper.ObjectToJSON(): " + ex.Message);
        }
    }
    private void CreateBall(string json)
    {
        JObject filters = new JObject();//实例化Json对象
        if (json != null)
            filters = JObject.Parse(json);//将Json串转换成对象
        JToken p1 = null;////获取Json串的第一个p中的条件 有几个P
        JToken p = null; //获取Json串的第二个p中的条件 如：m,p,e
        string strRedBall = filters["data"]["co"][0].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Trim();//获取Json串的红球的号叫码 如：【2,5,15,3,16,22】【14,5】
        string strBlueBall = filters["data"]["co"][1].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Trim();//获取Json串的蓝球的号叫码 如：【2,5,15,3,16,22】【14,5】
        BLL.ArrayListClass.SetRedBall(strRedBall);//将红球存入SetRedBall
        BLL.ArrayListClass.SetBlueBall(strBlueBall);//将蓝球存入SetBlueBall


        BLL.PrintBall printball = new BLL.PrintBall();
        int[] RedBallNum = printball.intArray(strRedBall.Split(','));
        int[] BlueBallNum = printball.intArray(strBlueBall.Split(','));
        jhArrayMySelf = printball.print(printball.combine(RedBallNum, 6), BlueBallNum);//通过自选的号码生成的投注号码(未经过过滤)
        ArrayList jhArray = jhArrayMySelf;//首先将自选的投注号码，存入公共的ArrayList,以便为每个过滤条件生成的投注号码，存入公共ArrayList
                                          //.Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"","").Trim();
                                          //string strZyxz = filters["data"]["cn"]["p"].ToString();
                                          //string ZyP = "",ZyM="";
                                          //让第二个P变成动态的
                                          //for(int r=0;r<filters["data"]["cn"]["p"])
        p1 = filters["data"]["cn"]["p"];
        JArray p1Array = (JArray)JsonConvert.DeserializeObject(p1.ToString());//将JToken转换成JArray,从而判断过滤条件的个数  p1Array下有多少个p
        JArray pArray = null;
        for (int r = 0; r < p1Array.Count; r++)
        {
            JToken pNei = null;//最内侧P
            bool e = false;
            string setf = "";//用于指标奇偶
                             //m为各个过滤条件的描述，如1、jh 奇号个数  f:为指标奇偶中的某一项指标，如f=hz 为号码和值，hv尾号过滤中设定的尾号,a为尾号个数过滤中true累加，false不累加,co为红蓝球号
            string n = "", x = "", v = "", d = "", err_n = "", err_x = "", m = "", f = "", hv = "", a = "", h = "", co = "";
            p = filters["data"]["cn"]["p"][r]["p"];//获取Json串的第二个p中的条件 如：m,p,e
            string nValues = "", xValues = "", rsValues = "";
            if (p.ToString().Contains("m") == false)
            {
                if (p.ToString().Contains("n") && p.ToString().Contains("x"))
                {
                    string pValue = p.ToString().Replace("\r", "").Replace("\n", "").Replace("{", "").Replace("}", "").Trim();
                    nValues = pValue.Substring(4, pValue.IndexOf("\"x\":") - 7).Trim();
                    xValues = pValue.Substring(pValue.IndexOf("\"x\":") + 4).Trim();
                    p = "[{\"e\": false,\"m\": \"zyxz\",\"p\": {\"n\":" + nValues + ",\"x\":" + xValues + "}}]";
                    pArray = (JArray)JsonConvert.DeserializeObject(p.ToString());
                }
                else if (p.ToString().Contains("n") && p.ToString().Contains("rs"))
                {
                    string pValue = p.ToString().Replace("\r", "").Replace("\n", "").Replace("{", "").Replace("}", "").Trim();
                    nValues = pValue.Substring(6, pValue.IndexOf("\"rs\":") - 10).Trim();
                    rsValues = pValue.Substring(pValue.IndexOf("\"rs\":") + 5).Trim();
                    p = "[{\"e\": false,\"m\": \"sjxz\",\"p\": {\"n\":" + nValues + ",\"rs\":" + rsValues + "}}]";
                    pArray = (JArray)JsonConvert.DeserializeObject(p.ToString());
                }
            }
            else
            {
                pArray = (JArray)JsonConvert.DeserializeObject(p.ToString());//将JToken转换成JArray,从而判断过滤条件的个数  pArray下有多少个 m,p,e
            }
            for (int i = 0; i < pArray.Count; i++)
            {
                m = pArray[i]["m"].ToString();//m为各个过滤条件的描述，如1、jh 奇号个数  2、dh 大号个数 3、hz 号码和值
                e = Convert.ToBoolean(pArray[i]["e"]);//是否容错
                if (e == true)//判断串有的e中否为false  为True时为容错
                {
                    err_n = pArray[i]["err"]["n"].ToString(); //容错起始值
                    err_x = pArray[i]["err"]["x"].ToString();//容错截止值 
                }
                if (m != "zyxz" && m != "sjxz")
                {


                    pNei = filters["data"]["cn"]["p"][r]["p"][i]["p"];//获取Json串的第三个p【最内侧的p】中的条件 如：v,h
                                                                      //1、jh 奇号个数  2、dh 大号个数 3、hz 号码和值 4、zd 最大号码 5、zx 最小号码 6、jhjj 跨度
                                                                      //7、zdjj 最大邻间距 8、zxjj 最小邻间距9、lh 连号个数 10、lhz 连号组数,11、wsz尾数组数
                }
                if (m == "jh" || m == "dh" || m == "hz" || m == "zd" || m == "zx" || m == "jhjj" || m == "zdjj" || m == "zxjj" || m == "lh" || m == "lhz" || m == "wsz")//奇号个数 p中元素为n,x
                {
                    n = filters["data"]["cn"]["p"][r]["p"][i]["p"]["n"].ToString();//起始值
                    x = filters["data"]["cn"]["p"][r]["p"][i]["p"]["x"].ToString();//截止值
                    jhArray = CgFilter(jhArray, Convert.ToInt32(n), Convert.ToInt32(x), false, 0, 0, m);//转到常规过滤出来的数据               
                }
                //1、jobl 奇偶比例  2、joxt 奇偶形态 3、zhbl 质合比例 4、zhxt 质合形态  twzs尾号过滤--同尾组数  twws尾号过滤--同尾尾号
                if (m == "jobl" || m == "joxt" || m == "zhbl" || m == "zhxt" || m == "dxbl" || m == "dxxt" || m == "wdxxt" || m == "twzs" || m == "twws")// v,d
                {
                    v = filters["data"]["cn"]["p"][r]["p"][i]["p"]["v"].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();//"v":[false,false,false,false,false,true,true]
                    d = filters["data"]["cn"]["p"][r]["p"][i]["p"]["d"].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Trim();//d=true 过滤  d=false 保留
                    jhArray = JoZhFilter(jhArray, v, d, false, 0, 0, m);//转到常规过滤出来的数据               
                }
                //zbjo 指标奇偶
                if (m == "zbjo")
                {
                    setf = filters["data"]["cn"]["p"][r]["p"][i]["p"]["set"].ToString();
                    JArray fArray = (JArray)JsonConvert.DeserializeObject(setf.ToString());
                    for (int ff = 0; ff < fArray.Count; ff++)
                    {
                        v = fArray[ff]["v"].ToString();
                        f = fArray[ff]["f"].ToString();
                        d = fArray[ff]["d"].ToString();
                        jhArray = ZbJoFilter(jhArray, v, d, false, 0, 0, m, f);//转到奇偶指标过滤出来的数据          
                    }
                }
                //【尾号过滤】--尾号个数
                if (m == "whgs")// v,d
                {
                    //v设定的尾号出现的个数
                    v = filters["data"]["cn"]["p"][r]["p"][i]["p"]["v"].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();//"v":[false,false,false,false,false,true,true]
                                                                                                                                                                                  //设定的尾号"hv":["5","7","9"] 则尾号分别是5,7,9
                    hv = filters["data"]["cn"]["p"][r]["p"][i]["p"]["hv"].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();//hv:["1","3","9"]设定的尾号
                                                                                                                                                                                    //次数是否累加 false：不累加 true：累加
                    a = filters["data"]["cn"]["p"][r]["p"][i]["p"]["a"].ToString();
                    jhArray = WhFilter(jhArray, v, a, hv, false, 0, 0, m);//转到常规过滤出来的数据               
                }

                //【尾号过滤】--尾号匹配
                if (m == "whpp")// v,d
                {
                    //v设定的尾号出现的个数
                    //"v":[false,false,false,false,false,true,true]
                    //设定的尾号"h":[false,false,false,true,false,false,true,false,false,false],
                    //[false,false,false,false,false,false,false,false,true,true]
                    v = filters["data"]["cn"]["p"][r]["p"][i]["p"]["v"].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
                    JToken hh = filters["data"]["cn"]["p"][r]["p"][i]["p"]["h"];
                    JArray hArray = (JArray)JsonConvert.DeserializeObject(hh.ToString());
                    string[] RedBlueWs = new string[7];//红球一至六加一蓝球的尾数【数组】
                    RedBlueWs[0] = hArray[0].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
                    RedBlueWs[1] = hArray[1].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
                    RedBlueWs[2] = hArray[2].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
                    RedBlueWs[3] = hArray[3].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
                    RedBlueWs[4] = hArray[4].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
                    RedBlueWs[5] = hArray[5].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
                    RedBlueWs[6] = hArray[6].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
                    jhArray = WhppFilter(jhArray, v, RedBlueWs, false, 0, 0, m);//转到常规过滤出来的数据               
                }
                if (m == "cc")//【高级过滤】--匹配过滤
                {

                    JToken setcc = filters["data"]["cn"]["p"][r]["p"][i]["p"]["set"].ToString();//【高级过滤】--匹配过滤set下的条件，h,co   h:为匹配个数  co：为红球，蓝球
                    JArray CCArray = (JArray)JsonConvert.DeserializeObject(setcc.ToString());
                    string Co1 = "", Co2 = "";
                    for (int cc = 0; cc < CCArray.Count; cc++)
                    {
                        h = CCArray[cc]["h"].ToString();//h:为匹配个数
                        co = CCArray[cc]["co"].ToString();//co：为红球，蓝球
                        JArray CoArray = (JArray)JsonConvert.DeserializeObject(co.ToString());
                        Co1 = CoArray[0].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();//红球
                        Co2 = CoArray[1].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();//蓝球
                        jhArray = GaoJiFilter(jhArray, h, Co1, Co2, false, 0, 0, m);//转到奇偶指标过滤出来的数据          
                    }
                }
                if (m == "cgfz")//【高级过滤】--分组过滤
                {
                    JToken setCgfz = filters["data"]["cn"]["p"][r]["p"][i]["p"]["set"].ToString();//【高级过滤】--分组过滤set下的条件，m,h[n,x],f   m:为匹配个数  h：n匹配起始值  h：x匹配截止值 f:每个过滤子项的名称描述
                    JArray CgfzArray = (JArray)JsonConvert.DeserializeObject(setCgfz.ToString());
                    string m_z = ""; //"m_z":[false,false,false,false,true,false,false] 为true的则为被勾选项
                    for (int ff = 0; ff < CgfzArray.Count; ff++)
                    {
                        //红球蓝球选项 如：勾选其中红球一与红球二，蓝球，则这个三个球做为过滤条件进行，子项过滤的条件
                        //"m_z":[false,false,false,false,true,false,false] 为true的则为被勾选项
                        m_z = CgfzArray[ff]["m"].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
                        n = CgfzArray[ff]["h"]["n"].ToString();//起始值
                        x = CgfzArray[ff]["h"]["x"].ToString();//截止值
                        f = CgfzArray[ff]["f"].ToString();//子项过滤描述名称
                        jhArray = GaoJi_CgfzFilter(jhArray, Convert.ToInt32(n), Convert.ToInt32(x), m_z, false, 0, 0, f);//转到奇偶指标过滤出来的数据
                    }
                }
                if (m == "qjgl")//【高级过滤】--区间过滤
                {
                    JToken setQjgl = filters["data"]["cn"]["p"][r]["p"][i]["p"]["set"].ToString();//【高级过滤】--区间过滤set下的条件，h,r[n,x],f   h:为匹配个数  r：n匹配起始值  r：x匹配截止值
                    JArray QjglArray = (JArray)JsonConvert.DeserializeObject(setQjgl.ToString());
                    for (int b = 0; b < QjglArray.Count; b++)
                    {
                        h = QjglArray[b]["h"].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();
                        n = QjglArray[b]["r"]["n"].ToString();//起始值
                        x = QjglArray[b]["r"]["x"].ToString();//截止值
                        jhArray = GaoJi_QjglFilter(jhArray, n, x, h, false, 0, 0, m);//转到奇偶指标过滤出来的数据
                    }
                }
                if (m == "dwgl")//【高级过滤】--定位过滤
                {
                    JToken setDwgl = filters["data"]["cn"]["p"][r]["p"][i]["p"]["set"].ToString();//【高级过滤】--定位过滤set下的条件，s["*","1","2","*","2","*","*"],g["*","1","2","*","2","*","*"],d   s:十位数  g：个位数  d：false 保留 true 滤除
                    JArray DwglArray = (JArray)JsonConvert.DeserializeObject(setDwgl.ToString());
                    string s = "", g = ""; //s 十位数 g 个位数
                    for (int b = 0; b < DwglArray.Count; b++)
                    {
                        //"s":["3","*","*","2","0","*","*"],"g":["*","*","2","1","2","*","*"],"d":true
                        d = DwglArray[b]["d"].ToString();
                        s = DwglArray[b]["s"].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();//十位值
                        g = DwglArray[b]["g"].ToString().Replace("\r", "").Replace("\n", "").Replace("[", "").Replace("]", "").Replace("\"", "").Trim();//个位值
                        jhArray = GaoJi_DwglFilter(jhArray, s, g, d, false, 0, 0, m);//转到奇偶指标过滤出来的数据
                    }
                }
                if (m == "zyxz")//自由选注
                {
                    jhArray = XzglFilter(jhArray, Convert.ToInt32(nValues), Convert.ToInt32(xValues), false, 0, 0, m);//转到常规过滤出来的数据   
                }
                if (m == "sjxz") //sjzs随机选注
                {
                    jhArray = XzglFilter(jhArray, Convert.ToInt32(nValues), 0, false, 0, 0, m);//转到常规过滤出来的数据
                }
            }
        }
        //jhArray.Add(jhArrayMySelf.Count);
        //将Json序列化
        DictionaryEntry[] BallandCount = new DictionaryEntry[2] { new DictionaryEntry("balls", jhArray), new DictionaryEntry("ballsCount", strBallsCount) };
        HttpContext.Current.Response.Write(JsonConvert.SerializeObject(BallandCount));
    }
    /// <summary>
    /// 【选择过滤】--自由选注与随机选注 
    /// </summary>
    /// <param name="AllBall">自选号码后生成的号码</param>
    /// <param name="n">起始值</param>
    /// <param name="x">截止值</param>
    /// <param name="e">e=false 不容错 e=true 容错</param>
    /// <param name="err_n">容错起始值</param>
    /// <param name="err_x">容错截止值</param>
    /// <param name="m">过滤描述 m=dwgl[定位过滤]过滤</param>
    /// <returns></returns>
    private ArrayList XzglFilter(ArrayList AllBall, int nn, int xx, bool e, int err_n, int err_x, string m)
    {
        ArrayList newArray = new ArrayList();

        if (m == "zyxz")//自由选注
        {
            if (nn > AllBall.Count)
            {
                nn = 0;
            }
            if (xx > AllBall.Count)
            {
                xx = AllBall.Count;
            }
            for (int i = nn - 1; i < xx; i++)//循环生成的投注号码
            {
                if (i == -1)
                {
                    //如果为负数则为0注
                    break;
                }
                else
                {
                    newArray.Add(AllBall[i]);
                }
            }
        }
        else
        {

            if (nn > AllBall.Count)
            {
                nn = AllBall.Count;
                for (int t = 0; t < nn; t++)
                {
                    newArray.Add(AllBall[t]);
                }
            }
            else
            {
                int[] index = new int[AllBall.Count];
                for (int i = 0; i < AllBall.Count; i++)
                    index[i] = i;
                Random r = new Random();
                //用来保存随机生成的不重复的10个数
                int[] result = new int[nn];
                int site = AllBall.Count;//设置下限
                int id;
                for (int j = 0; j < nn; j++)
                {
                    id = r.Next(1, site - 1);
                    //在随机位置取出一个数，保存到结果数组
                    result[j] = index[id];
                    //最后一个数复制到当前位置
                    index[id] = index[site - 1];
                    newArray.Add(AllBall[result[j]]); //向newArray中增加投注号码
                                                      //位置的下限减少一
                    site--;
                }
            }
        }
        BLL.ArrayListClass.SetArrayList(newArray);
        strBallsCount += newArray.Count.ToString() + ",";
        return newArray;
    }

    /// <summary>
    /// 【高级过滤】--定位过滤
    /// </summary>
    /// <param name="AllBall">自选号码后生成的号码</param>
    /// <param name="n">起始值</param>
    /// <param name="x">截止值</param>
    /// <param name="e">e=false 不容错 e=true 容错</param>
    /// <param name="err_n">容错起始值</param>
    /// <param name="err_x">容错截止值</param>
    /// <param name="m">过滤描述 m=dwgl[定位过滤]过滤</param>
    /// <returns></returns>
    private ArrayList GaoJi_DwglFilter(ArrayList AllBall, string nn, string xx, string d, bool e, int err_n, int err_x, string m)
    {
        ArrayList newArray = new ArrayList();
        string[] ShiWeiArray = nn.Split(',');//十位分隔
        string[] GeWeiArray = xx.Split(',');//个位分隔
        int STT = 0, GTT = 0;
        int SttCount = 0, GttCount = 0;//用来统计十位数个位数有几个不是“*”的个数
        for (int i = 0; i < AllBall.Count; i++)//循环生成的投注号码
        {
            string[] strBall = AllBall[i].ToString().Split(',');//将每一注号码串中的‘，’分隔开，从而统计奇号个数
            for (int j = 0; j < strBall.Length - 1; j++)//只包含红球
            {
                if (m == "dwgl")
                {
                    if (ShiWeiArray[j].ToString().Trim() != "*")
                    {
                        if (strBall[j].Substring(0, 1) == ShiWeiArray[j].Trim())//判断十位数字是否相同
                        {
                            STT++;
                        }
                        SttCount++;
                    }


                    if (GeWeiArray[j].ToString().Trim() != "*")
                    {
                        if (strBall[j].Substring(1, 1) == GeWeiArray[j].Trim())//判断个位数字是否相同
                        {
                            GTT++;
                        }
                        GttCount++;
                    }

                }
            }
            //---------For 外---------------
            if (m == "dwgl")
            {
                if (d.ToLower() == "false")//保留
                {
                    if (STT == SttCount && GTT == GttCount)
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                else
                {
                    if (STT != SttCount || GTT != GttCount)
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                STT = 0; GTT = 0; GttCount = 0; SttCount = 0;
            }
        }
        BLL.ArrayListClass.SetArrayList(newArray);
        strBallsCount += newArray.Count.ToString() + ",";
        return newArray;
    }


    /// <summary>
    /// 【高级过滤】--区间过滤
    /// </summary>
    /// <param name="AllBall">自选号码后生成的号码</param>
    /// <param name="n">起始值</param>
    /// <param name="x">截止值</param>
    /// <param name="e">e=false 不容错 e=true 容错</param>
    /// <param name="err_n">容错起始值</param>
    /// <param name="err_x">容错截止值</param>
    /// <param name="m">过滤描述 m=cgfz[分组]过滤</param>
    /// <returns></returns>
    private ArrayList GaoJi_QjglFilter(ArrayList AllBall, string nn, string xx, string h, bool e, int err_n, int err_x, string m)
    {
        ArrayList newArray = new ArrayList();
        int n = Convert.ToInt32(nn);
        int x = Convert.ToInt32(xx);
        int Count = 0;//个数值
        string CheckItemString = "";//被勾选的项，从而判断勾选的项是红球，还是蓝球
        CheckItemString = TrueConvertString(h);//拆分串"false,false,true,true,false,false,false" 次数为0,1,2,3,4,5,6
        string[] CheckItemArray = null;
        if (CheckItemString != null && CheckItemString != "")
        {
            CheckItemArray = CheckItemString.Substring(0, CheckItemString.Length - 1).Split(',');//将自定义的匹配次数，存入数组
        }
        string[] ShiWeiArray = nn.Split(',');//十位分隔
        string[] GeWeiArray = xx.Split(',');//个位分隔
        bool STT = false, GTT = false;
        for (int i = 0; i < AllBall.Count; i++)//循环生成的投注号码
        {
            string[] strBall = AllBall[i].ToString().Split(',');//将每一注号码串中的‘，’分隔开，从而统计奇号个数
            for (int j = 0; j < strBall.Length - 1; j++)//只包含红球
            {
                if (m == "qjgl")
                {
                    if (Convert.ToInt32(strBall[j]) >= n && Convert.ToInt32(strBall[j]) <= x)
                    {
                        Count++;
                    }
                }

                if (m == "dwgl")
                {

                    if (ShiWeiArray[j].ToString() != "*")
                    {

                        if (Convert.ToInt32(strBall[j]) > 9)//大于9则是两位数  十位，个位
                        {

                            if (Convert.ToInt32(strBall[j].Substring(0, 1)) == Convert.ToInt32(ShiWeiArray[j]))//判断十位数字是否相同
                            {
                                STT = true;
                            }
                        }

                    }
                    else
                    {
                        STT = true;
                    }

                    if (GeWeiArray[j].ToString() != "*")
                    {
                        if (Convert.ToInt32(strBall[j].Substring(1, 1)) == Convert.ToInt32(GeWeiArray[j]))//判断十位数字是否相同
                        {
                            GTT = true;
                        }
                    }
                    else
                    {
                        GTT = true;
                    }

                }
            }
            //---------For 外---------------
            if (m == "qjgl")
            {
                for (int t = 0; t < CheckItemArray.Length; t++)
                {
                    if (CheckItemArray.Length == 1)
                    {
                        if (Count == Convert.ToInt32(CheckItemArray[t]))
                        {
                            newArray.Add(AllBall[i]);
                            break;
                        }
                    }
                    else
                    {
                        if (Count >= Convert.ToInt32(CheckItemArray[t]))
                        {
                            newArray.Add(AllBall[i]);
                            break;
                        }
                    }
                }
                Count = 0;
            }
            if (m == "dwgl")
            {
                if (STT == true && GTT == true)
                {
                    newArray.Add(AllBall[i]);
                }
                STT = false; GTT = false;
            }
        }
        BLL.ArrayListClass.SetArrayList(newArray);
        strBallsCount += newArray.Count.ToString() + ",";
        return newArray;
    }

    /// <summary>
    /// 【高级过滤】--分组过滤
    /// </summary>
    /// <param name="AllBall">自选号码后生成的号码</param>
    /// <param name="n">起始值</param>
    /// <param name="x">截止值</param>
    /// <param name="e">e=false 不容错 e=true 容错</param>
    /// <param name="err_n">容错起始值</param>
    /// <param name="err_x">容错截止值</param>
    /// <param name="m">过滤描述 m=cgfz[分组]过滤</param>
    /// <param name="f">过滤子项描述 f=dh[大号个数]过滤</param>
    /// <returns></returns>
    private ArrayList GaoJi_CgfzFilter(ArrayList AllBall, int n, int x, string m_z, bool e, int err_n, int err_x, string m)
    {
        //1、jh 奇号个数  2、dh 大号个数 3、hz 号码和值 4、zd 最大号码 5、zx 最小号码 6、jhjj 跨度 
        //7、zdjj 最大邻间距 8、zxjj 最小邻间距9、lh 连号个数 10、lhz 连号组数，11、wsz尾数组数
        ArrayList newArray = new ArrayList();
        int jhCount = 0, dhCount = 0, hzSum = 0, zdNum = 0, zxNum = 34, jhjjZhi = 0, zdjjZhi = 0, zxjjZhi = 0, lhCount = 0, lhzCount = 0, wszCount = 0;//统计奇号个数
        string strZdjj = "";
        string[] m_zArray = m_z.Split(',');//拆分串"false,false,true,true,false,false,false" 次数为0,1,2,3,4,5,6
        string CheckItem = "";//被勾选的项，从而判断勾选的项是红球，还是蓝球
        if (m_zArray[0].Trim().ToLower() == "true")
        {
            CheckItem += "0,";
        }
        if (m_zArray[1].Trim().ToLower() == "true")
        {
            CheckItem += "1,";
        }
        if (m_zArray[2].Trim() == "true")
        {
            CheckItem += "2,";
        }
        if (m_zArray[3].Trim().ToLower() == "true")
        {
            CheckItem += "3,";
        }
        if (m_zArray[4].Trim().ToLower() == "true")
        {
            CheckItem += "4,";
        }
        if (m_zArray[5].Trim().ToLower() == "true")
        {
            CheckItem += "5,";
        }
        if (m_zArray[6].Trim().ToLower() == "true")
        {
            CheckItem += "6,";
        }
        string[] CheckItemArray = CheckItem.Substring(0, CheckItem.Length - 1).Split(',');
        for (int i = 0; i < AllBall.Count; i++)//循环生成的投注号码
        {
            string[] strBall = AllBall[i].ToString().Split(',');//将每一注号码串中的‘，’分隔开，从而统计奇号个数
            for (int j = 0; j < strBall.Length; j++)//某些过滤条件既包含 蓝球，又包含红球
            {
                if (m_zArray[j].ToString().Trim().ToLower() == "true")
                {
                    if (j != strBall.Length - 1)//只针对红球，所以循环长度减1
                    {
                        for (int s = 0; s < CheckItemArray.Length; s++)
                        {
                            if (m == "jhlx")//奇号连续个数【只统计红球】
                            {
                                if (s == 0)
                                {
                                    if (Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s])]) % 2 != 0 && Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s + 1])]) % 2 != 0)//不能被2整除的，则为奇数
                                    {
                                        jhCount++;//统计奇数个数累加
                                    }
                                }
                                else if (s == CheckItemArray.Length - 1)
                                {
                                    if (Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s])]) % 2 != 0 && Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s - 1])]) % 2 != 0)//不能被2整除的，则为奇数
                                    {
                                        jhCount++;//统计奇数个数累加
                                    }
                                }
                                else
                                {
                                    if ((Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s])]) % 2 != 0 && Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s + 1])]) % 2 != 0)
                                       || (Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s])]) % 2 != 0 && Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s - 1])]) % 2 != 0))
                                    {
                                        jhCount++;//统计奇数个数累加
                                    }
                                }

                            }
                            if (m == "dhlx")//大号连续个数【只统计红球】//号码>=17，则为大数
                            {
                                if (s == 0)
                                {
                                    if (Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s])]) >= 17 && Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s + 1])]) >= 17)//号码>=17，则为大数
                                    {
                                        dhCount++;//统计大号个数累加
                                    }
                                }
                                else if (s == CheckItemArray.Length - 1)
                                {
                                    if (Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s])]) >= 17 && Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s - 1])]) >= 17)//号码>=17，则为大数
                                    {
                                        dhCount++;//统计大号个数累加
                                    }
                                }
                                else
                                {

                                    if ((Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s])]) >= 17 && Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s + 1])]) >= 17)
                                        || (Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s])]) >= 17 && Convert.ToInt32(strBall[Convert.ToInt32(CheckItemArray[s - 1])]) >= 17))
                                    {
                                        dhCount++;//统计大号个数累加
                                    }
                                }
                            }
                        }

                        if (m == "jh")//奇号个数
                        {
                            if (Convert.ToInt32(strBall[j]) % 2 != 0)//不能被2整除的，则为奇数
                            {
                                jhCount++;//统计奇数个数累加
                            }
                        }
                        if (m == "dh")//大号个数
                        {
                            if (Convert.ToInt32(strBall[j]) >= 17)//号码>=17，则为大数
                            {
                                dhCount++;//统计大号个数累加
                            }
                        }
                        if (m == "hz")//号码和值
                        {
                            hzSum += Convert.ToInt32(strBall[j]);//统计大号个数累加
                        }
                        if (m == "zd")//最大号码
                        {
                            if (zdNum < Convert.ToInt32(strBall[j]))
                            {
                                zdNum = Convert.ToInt32(strBall[j]);//统计最大号码
                            }
                        }
                        if (m == "zx")//最小号码
                        {

                            if (Convert.ToInt32(strBall[j]) < zxNum)
                            {
                                zxNum = Convert.ToInt32(strBall[j]);//统计最小号码
                            }
                        }
                        if (m == "jhjj")//跨度（最大号与最小号的差值）
                        {
                            if (zdNum < Convert.ToInt32(strBall[j]))
                            {
                                zdNum = Convert.ToInt32(strBall[j]);//跨度（最大号与最小号的差值）--统计最大号码
                            }
                            if (Convert.ToInt32(strBall[j]) < zxNum)
                            {
                                zxNum = Convert.ToInt32(strBall[j]);////跨度（最大号与最小号的差值）--统计最小号码
                            }
                            jhjjZhi = zdNum - zxNum;
                        }
                        if (m == "zdjj")//最大邻间距（相邻两个红球号码之间的最大值）
                        {
                            if (j == 0)
                            {
                                zdjjZhi = Math.Abs(Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j + 1]));
                                strZdjj = zdjjZhi + ",";
                            }
                            else
                            {
                                if (j <= strBall.Length - 2)
                                {
                                    zdjjZhi = Math.Abs(Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j - 1]));
                                    strZdjj += zdjjZhi + ",";
                                    if (j == strBall.Length - 2)
                                    {
                                        string[] zdjjShuZu = strZdjj.Substring(0, strZdjj.Length - 1).Split(',');
                                        for (int xx = 0; xx < zdjjShuZu.Length; xx++)
                                        {
                                            if (zdNum < Convert.ToInt32(zdjjShuZu[xx]))
                                            {
                                                zdNum = Convert.ToInt32(zdjjShuZu[xx]);//统计最大邻间距号码
                                            }
                                        }
                                    }
                                }
                            }

                        }
                        if (m == "zxjj")//最小邻间距（相邻两个红球号码之间的最小值）
                        {
                            if (j == 0)
                            {
                                zxjjZhi = Math.Abs(Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j + 1]));
                                strZdjj = zxjjZhi + ",";
                            }
                            else
                            {
                                if (j <= strBall.Length - 2)
                                {
                                    zxjjZhi = Math.Abs(Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j - 1]));
                                    strZdjj += zxjjZhi + ",";
                                    if (j == strBall.Length - 2)
                                    {
                                        string[] zxjjShuZu = strZdjj.Substring(0, strZdjj.Length - 1).Split(',');
                                        for (int xx = 0; xx < zxjjShuZu.Length; xx++)
                                        {
                                            if (Convert.ToInt32(zxjjShuZu[xx]) < zxNum)
                                            {
                                                zxNum = Convert.ToInt32(zxjjShuZu[xx]);//统计最小邻间距号码
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (m == "lh")//连号
                        {
                            if (j > 0 && j < 6)
                            {
                                if (Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j - 1]) == 1)
                                {
                                    lhCount++;
                                }
                            }
                        }
                        if (m == "lhz")//连号组数
                        {
                            if (j > 0 && j < 6)
                            {
                                if (Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j - 1]) == 1)
                                {
                                    lhzFlag++;
                                }
                                if (Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j - 1]) != 1 || j == 5)
                                {
                                    if (lhzFlag != 0)
                                    {
                                        lhzFlag = 0;
                                        lhzCount++;
                                    }
                                }

                                if (lhzFlag == 5)
                                {
                                    lhzFlag = 0;
                                    lhzCount = 1;
                                }
                            }
                        }
                        if (m == "whz") //尾号和值
                        {
                            hzSum += Convert.ToInt32(strBall[j].Substring(1, 1));
                        }
                        if (m == "zxwh")//最小尾号
                        {
                            if (Convert.ToInt32(strBall[j].Substring(1, 1)) < zxNum)
                            {
                                zxNum = Convert.ToInt32(strBall[j]);//统计最小号码
                            }
                        }
                        if (m == "zdwh")//最大尾号
                        {
                            if (hzSum < Convert.ToInt32(strBall[j].Substring(1, 1)))
                            {
                                hzSum = Convert.ToInt32(strBall[j]);//统计最大号码
                            }
                        }
                        if (m == "yqhz")//一区和值
                        {
                            if (Convert.ToInt32(strBall[j]) > 0 && Convert.ToInt32(strBall[j]) < 12)
                            {
                                hzSum += Convert.ToInt32(strBall[j].Substring(1, 1));
                            }
                        }
                        if (m == "eqhz")//二区和值
                        {
                            if (Convert.ToInt32(strBall[j]) > 11 && Convert.ToInt32(strBall[j]) < 23)
                            {
                                hzSum += Convert.ToInt32(strBall[j].Substring(1, 1));
                            }
                        }
                        if (m == "sqhz")//三区和值
                        {
                            if (Convert.ToInt32(strBall[j]) > 22 && Convert.ToInt32(strBall[j]) < 34)
                            {
                                hzSum += Convert.ToInt32(strBall[j].Substring(1, 1));
                            }
                        }
                        if (m == "wsz")//尾数组数
                        {
                            if (j == 0)
                            {
                                strWs = strBall[j].Substring(1, 1);
                            }
                            if (j > 0 && j < 6)
                            {
                                if (strWs.Contains(strBall[j].Substring(1, 1)))
                                {

                                }
                                else
                                {
                                    wszCount++;
                                    strWs += strBall[j].Substring(1, 1);
                                }
                                if (j == 5)
                                {
                                    wszCount++;
                                }
                            }
                        }
                    }
                    if (m == "c3hz")//除3余数和
                    {
                        if (Convert.ToInt32(strBall[j]) % 3 != 0)//不能被3整除,则求除3余数的和
                        {
                            hzSum += Convert.ToInt32(strBall[j]) % 3;
                        }
                    }
                    if (m == "c4hz")//除4余数和
                    {
                        if (Convert.ToInt32(strBall[j]) % 4 != 0)//不能被4整除,则求除4余数的和
                        {
                            hzSum += Convert.ToInt32(strBall[j]) % 4;
                        }
                    }
                    if (m == "c5hz")//除5余数和
                    {
                        if (Convert.ToInt32(strBall[j]) % 5 != 0)//不能被5整除,则求除5余数的和
                        {
                            hzSum += Convert.ToInt32(strBall[j]) % 5;
                        }
                    }
                    if (m == "c6hz")//除6余数和
                    {
                        if (Convert.ToInt32(strBall[j]) % 6 != 0)//不能被6整除,则求除6余数的和
                        {
                            hzSum += Convert.ToInt32(strBall[j]) % 6;
                        }
                    }
                    if (m == "c7hz")//除7余数和
                    {
                        if (Convert.ToInt32(strBall[j]) % 7 != 0)//不能被7整除,则求除7余数的和
                        {
                            hzSum += Convert.ToInt32(strBall[j]) % 7;
                        }
                    }
                    if (m == "c8hz")//除8余数和
                    {
                        if (Convert.ToInt32(strBall[j]) % 8 != 0)//不能被8整除,则求除8余数的和
                        {
                            hzSum += Convert.ToInt32(strBall[j]) % 8;
                        }
                    }
                    if (m == "c9hz")//除9余数和
                    {
                        if (Convert.ToInt32(strBall[j]) % 9 != 0)//不能被9整除,则求除9余数的和
                        {
                            hzSum += Convert.ToInt32(strBall[j]) % 9;
                        }
                    }
                }
            }
            //------------------for外--------------------------
            if (m == "jh" || m == "jhlx")//奇号个数与奇号连续个数
            {
                if (jhCount >= n && jhCount <= x) //如果满足过滤条件则接投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                jhCount = 0;
            }
            if (m == "dh" || m == "dhlx")//大号个数与大号连续个数
            {
                if (dhCount >= n && dhCount <= x) //如果满足过滤条件则接投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }

                dhCount = 0;
            }
            if (m == "hz" || m == "whz" || m == "zdwh" || m == "yqhz" || m == "eqhz" || m == "sqhz" || m == "c3hz" || m == "c4hz" || m == "c5hz" || m == "c6hz" || m == "c7hz" || m == "c8hz" || m == "c9hz")//号码和值,尾号和值，最大尾号，一区和值，二区和值，三区和值,除3至9的余数和值
            {
                if (hzSum >= n && hzSum <= x) //如果满足过滤条件则接投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                hzSum = 0;
            }

            if (m == "zd")//最大号码
            {
                if (zdNum >= n && zdNum <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }

                zdNum = 0;
            }
            if (m == "zx" || m == "zxwh")//最小号码，最小尾号
            {
                if (zxNum >= n && zxNum <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                zxNum = 34;
            }
            if (m == "jhjj")//跨度
            {
                if (jhjjZhi >= n && jhjjZhi <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                zdNum = 0;
                zxNum = 34;
                jhjjZhi = 0;
            }
            if (m == "zdjj")//最大邻间距
            {
                if (zdNum >= n && zdNum <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                zdNum = 0;
            }
            if (m == "zxjj")//最小邻间距
            {
                if (zxNum >= n && zxNum <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                zxNum = 34;
            }

            if (m == "lh")//连号个数
            {
                if (lhCount >= n && lhCount <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                lhCount = 0;
            }
            if (m == "lhz")//连号组数
            {
                if (lhzCount >= n && lhzCount <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                lhzCount = 0;
            }
            if (m == "wsz")//尾数组数
            {
                if (wszCount >= n && wszCount <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                wszCount = 0;
            }
        }
        BLL.ArrayListClass.SetArrayList(newArray);
        strBallsCount += newArray.Count.ToString() + ",";
        return newArray;
    }


    /// <summary>
    /// 【高级过滤】--匹配过滤
    /// </summary>
    /// <param name="AllBall">自选号码后生成的号码</param>
    /// <param name="h">设定的尾号出现的个数"v":[false,false,false,true,false,false,false] 从0开始 ，true为3，则次数为3次</param>
    /// <param name="coBall">一维数组是红球，二维数组是蓝球</param>
    /// <param name="e">e=false 不容错 e=true 容错</param>
    /// <param name="err_n">容错起始值</param>
    /// <param name="err_x">容错截止值</param>
    /// <param name="m">过滤描述 m=dh[大号个数]过滤</param>
    /// <returns></returns>
    private ArrayList GaoJiFilter(ArrayList AllBall, string h, string Co1, string Co2, bool e, int err_n, int err_x, string m)
    {
        ArrayList newArray = new ArrayList();
        //string[] vArray= h.Split(',');//拆分串"false,false,true,true,false,false,false" 次数为0,1,2,3,4,5,6
        string CheckItemString = "";//被勾选的项，从而判断勾选的项是红球，还是蓝球
        CheckItemString = TrueConvertString(h);//拆分串"false,false,true,true,false,false,false" 次数为0,1,2,3,4,5,6
        string[] strRedBall = null;
        string[] strGreenBall = null;
        int Count = 0;
        strRedBall = Co1.Split(',');//红球
        strGreenBall = Co2.Split(',');//蓝球
        string strRed = "", strGreen = "";
        if (Co1.Contains(","))
        {
            strRedBall = Co1.Split(',');
        }
        else
        {
            strRed = Co1;
        }

        if (Co2.Contains(","))
        {
            strGreenBall = Co2.Split(',');
        }
        else
        {
            strGreen = Co2;
        }
        string[] CishuArray = null;
        if (CheckItemString != null && CheckItemString != "")
        {
            CishuArray = CheckItemString.Substring(0, CheckItemString.Length - 1).Split(',');//将自定义的匹配次数，存入数组
        }
        string glRedBall = "", glBlueBall = "";
        for (int i = 0; i < AllBall.Count; i++)//循环生成的投注号码
        {
            if (!String.IsNullOrEmpty(Co1))
            {
                //计算红球
                if (Co1.Contains(","))
                {
                    strRedBall = Co1.Split(',');
                    for (int j = 0; j < strRedBall.Length; j++)
                    {
                        if (Convert.ToInt32(strRedBall[j].Trim()) < 10)
                        {
                            glRedBall = "0" + strRedBall[j].Trim();
                        }
                        else
                        {
                            glRedBall = strRedBall[j].Trim();
                        }
                        if (AllBall[i].ToString().Contains(glRedBall + ","))//判断红球
                        {
                            Count++;
                        }
                    }
                }
                else
                {
                    if (AllBall[i].ToString().Contains(Co1.Trim() + ","))//判断红球
                    {
                        Count++;
                    }
                }
            }
            if (!String.IsNullOrEmpty(Co2))
            {
                //计算蓝球
                if (Co2.Contains(","))
                {
                    strGreenBall = Co2.Split(',');
                    for (int x = 0; x < strGreenBall.Length; x++)
                    {
                        if (AllBall[i].ToString().Substring(AllBall[i].ToString().LastIndexOf(',')).Contains("," + strGreenBall[x]))//将蓝球号码截出
                        {
                            Count++;
                        }
                    }
                }
                else
                {
                    if (AllBall[i].ToString().Contains("," + Co2))//将蓝球号码截出
                    {
                        Count++;
                    }
                }
            }

            int Temp = 0;
            for (int t = 0; t < CishuArray.Length; t++)
            {
                if (Temp < Convert.ToInt32(CishuArray[t]))//取出数组中的最大值
                {
                    Temp = Convert.ToInt32(CishuArray[t]);
                }
            }
            for (int t = 0; t < CishuArray.Length; t++)
            {
                if (CishuArray.Length == 1)
                {
                    if (Count == Convert.ToInt32(CishuArray[t]))
                    {
                        newArray.Add(AllBall[i]);
                        break;
                    }
                }
                else
                {
                    if (Count > Temp)
                    {
                        break;
                    }
                    if (Count >= Convert.ToInt32(CishuArray[t]))
                    {
                        newArray.Add(AllBall[i]);
                        break;
                    }
                }
            }
            Count = 0;
        }
        BLL.ArrayListClass.SetArrayList(newArray);
        strBallsCount += newArray.Count.ToString() + ",";
        return newArray;
    }

    /// <summary>
    /// 【尾号过滤】
    /// </summary>
    /// <param name="AllBall">自选号码后生成的号码</param>
    /// <param name="v">设定的尾号出现的个数"v":[false,false,false,true,false,false,false] 从0开始 ，true为3，则次数为3次</param>
    /// <param name="h">//红球一至六加一蓝球的尾数【数组】</param>
    /// <param name="e">e=false 不容错 e=true 容错</param>
    /// <param name="err_n">容错起始值</param>
    /// <param name="err_x">容错截止值</param>
    /// <param name="m">过滤描述 m=dh[大号个数]过滤</param>
    /// <returns></returns>
    private ArrayList WhppFilter(ArrayList AllBall, string v, string[] h, bool e, int err_n, int err_x, string m)
    {
        ArrayList newArray = new ArrayList();
        string BallWs = "";//投注号码尾数
        string strSetBall = "";//自定义号码
        string[] SetBallWs = new string[7];//自定义号码数组，如【1,5,6,5,8,9,3】
                                           //string[] vArray = null; //过滤条件
        int Count = 0;//统计尾号匹配个数
                      //将h中所对应的True与False换成自定义对应的尾号
                      //vArray = v.Split(',');//拆分串"false,false,true,true,false,false,false" 次数为0,1,2,3,4,5,6
        string CheckItemString = "";//被勾选的项，从而判断勾选的项是红球，还是蓝球
        CheckItemString = TrueConvertString(v);//拆分串"false,false,true,true,false,false,false" 次数为0,1,2,3,4,5,6
        for (int k = 0; k < h.Length; k++)//h为自定义7个球的尾号【共7行】false,false,false,true,false,false,false,false,false,false
        {
            string[] ball = h[k].Split(',');//自定义每一项点击的尾数 7行中每一行设置的尾数是多少
            for (int x = 0; x < ball.Length; x++)
            {
                if (ball[x].ToString().Trim().ToLower() == "true")
                {
                    strSetBall += x + ",";//每一行自定义的尾数存下来 1,2,4
                }
            }
            try
            {
                SetBallWs[k] = strSetBall.Substring(0, strSetBall.Length - 1);//去掉尾部的逗号，将第一行自定义的尾数存入数组中
                strSetBall = "";
            }
            catch
            {
                break;
            }
        }
        string[] CishuArray = null;
        if (CheckItemString != null && CheckItemString != "")
        {
            CishuArray = CheckItemString.Substring(0, CheckItemString.Length - 1).Split(',');//将自定义的匹配次数，存入数组
        }

        for (int i = 0; i < AllBall.Count; i++)//循环生成的投注号码
        {
            string[] strBall = AllBall[i].ToString().Split(',');//将每一注号码串中的‘，’分隔开
            for (int j = 0; j < strBall.Length; j++)//包含蓝球
            {
                BallWs += strBall[j].Substring(1, 1) + ",";//截取出投注号码的尾号，并用逗号分隔
            }
            string[] BallWsOne = BallWs.Substring(0, BallWs.Length - 1).Split(',');//将投注号码的尾号存入数组中
            try
            {
                for (int pp = 0; pp < BallWsOne.Length; pp++)
                {
                    if (SetBallWs[pp].Contains(BallWsOne[pp]))//如果自定义的尾号中包含投注号码的尾号，则次数+1
                    {
                        Count++;//统计出一注号码尾号，与自定义尾号匹配个数
                                //continue;
                    }
                }
            }
            catch
            {
                break;
            }
            for (int t = 0; t < CishuArray.Length; t++)
            {
                if (CishuArray.Length == 1)
                {
                    if (Count == Convert.ToInt32(CishuArray[t]))
                    {
                        newArray.Add(AllBall[i]);
                        break;
                    }
                }
                else
                {
                    if (Count >= Convert.ToInt32(CishuArray[t]))
                    {
                        newArray.Add(AllBall[i]);
                        break;
                    }
                }
            }
            BallWs = "";
            Count = 0;
        }
        BLL.ArrayListClass.SetArrayList(newArray);
        strBallsCount += newArray.Count.ToString() + ",";
        return newArray;
    }

    /// <summary>
    /// 【尾号过滤】
    /// </summary>
    /// <param name="AllBall">自选号码后生成的号码</param>
    /// <param name="v">设定的尾号出现的个数"v":[false,false,false,true,false,false,false] 从0开始 ，true为3，则次数为3次</param>
    /// <param name="a">次数是否累加 false：不累加 true：累加</param>
    /// <param name="hv">设定的尾号"hv":["5","7","9"] 则尾号分别是5,7,9</param>
    /// <param name="e">e=false 不容错 e=true 容错</param>
    /// <param name="err_n">容错起始值</param>
    /// <param name="err_x">容错截止值</param>
    /// <param name="m">过滤描述 m=dh[大号个数]过滤</param>
    /// <returns></returns>
    private ArrayList WhFilter(ArrayList AllBall, string v, string a, string hv, bool e, int err_n, int err_x, string m)
    {
        ArrayList newArray = new ArrayList();
        string[] hvArray = hv.Split(',');
        //string[] vArray = null; //过滤条件
        int AddCount = 0;//尾号累加次数
        string aa = "";
        for (int i = 0; i < AllBall.Count; i++)//循环生成的投注号码
        {
            string[] strBall = AllBall[i].ToString().Split(',');//将每一注号码串中的‘，’分隔开
            for (int j = 0; j < strBall.Length - 1; j++)//只针对红球，所以循环长度减1
            {
                if (m == "whgs")//尾号个数
                {
                    for (int ss = 0; ss < hvArray.Length; ss++)//hvArray自定义的尾数
                    {
                        if (Convert.ToInt32(strBall[j].Substring(1, 1)) == Convert.ToInt32(hvArray[ss]))//如果截取的尾数和设定的尾数相同
                        {
                            if (a.ToLower() == "true")//true累加
                            {
                                AddCount++;
                            }
                            else//不累加
                            {
                                if (AddCount == 0)
                                {
                                    AddCount++;
                                    aa = Convert.ToInt32(strBall[j].Substring(1, 1)).ToString();
                                }
                                else
                                {
                                    if (aa.Contains(Convert.ToInt32(strBall[j].Substring(1, 1)).ToString()))
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        AddCount++;
                                        aa += "," + Convert.ToInt32(strBall[j].Substring(1, 1)).ToString();
                                    }


                                }
                            }
                        }
                    }
                }

            }
            //---------For------------
            if (m == "whgs")//尾号个数
            {
                string CheckItemString = "";//被勾选的项，从而判断勾选的项是红球，还是蓝球
                CheckItemString = TrueConvertString(v);//拆分串"false,false,true,true,false,false,false" 次数为0,1,2,3,4,5,6
                string[] CishuArray = null;
                if (CheckItemString != "" && CheckItemString != null)
                {
                    CishuArray = CheckItemString.Substring(0, CheckItemString.Length - 1).Split(',');
                }
                else
                {
                    break;
                }

                for (int t = 0; t < CishuArray.Length; t++)
                {
                    if (AddCount == Convert.ToInt32(CishuArray[t]))//当尾数的个数，正好等于在界面上勾选累加个数时，则符合条件
                    {
                        newArray.Add(AllBall[i]);
                        break;
                    }

                }
                AddCount = 0;
            }
        }
        BLL.ArrayListClass.SetArrayList(newArray);
        strBallsCount += newArray.Count.ToString() + ",";
        return newArray;
    }



    /// <summary>
    /// 常规过滤
    /// </summary>
    /// <param name="AllBall">自选号码后生成的号码</param>
    /// <param name="n">过滤条件起始值</param>
    /// <param name="x">过滤条件截止值</param>
    /// <param name="e">e=false 不容错 e=true 容错</param>
    /// <param name="err_n">容错起始值</param>
    /// <param name="err_x">容错截止值</param>
    /// <param name="m">过滤描述 m=dh[大号个数]过滤</param>
    /// <returns></returns>
    private ArrayList CgFilter(ArrayList AllBall, int n, int x, bool e, int err_n, int err_x, string m)
    {
        //1、jh 奇号个数  2、dh 大号个数 3、hz 号码和值 4、zd 最大号码 5、zx 最小号码 6、jhjj 跨度 
        //7、zdjj 最大邻间距 8、zxjj 最小邻间距9、lh 连号个数 10、lhz 连号组数，11、wsz尾数组数
        ArrayList newArray = new ArrayList();
        int jhCount = 0, dhCount = 0, hzSum = 0, zdNum = 0, zxNum = 34, jhjjZhi = 0, zdjjZhi = 0, zxjjZhi = 0, lhCount = 0, lhzCount = 0, wszCount = 0;//统计奇号个数
        string strZdjj = "";
        for (int i = 0; i < AllBall.Count; i++)//循环生成的投注号码
        {
            string[] strBall = AllBall[i].ToString().Split(',');//将每一注号码串中的‘，’分隔开，从而统计奇号个数
            for (int j = 0; j < strBall.Length - 1; j++)//只针对红球，所以循环长度减1
            {
                if (m == "jh")//奇号个数
                {
                    if (Convert.ToInt32(strBall[j]) % 2 != 0)//不能被2整除的，则为奇数
                    {
                        jhCount++;//统计奇数个数累加
                    }
                }
                if (m == "dh")//大号个数
                {
                    if (Convert.ToInt32(strBall[j]) >= 17)//号码>=17，则为大数
                    {
                        dhCount++;//统计大号个数累加
                    }
                }
                if (m == "hz")//号码和值
                {
                    hzSum += Convert.ToInt32(strBall[j]);//统计大号个数累加
                }
                if (m == "zd")//最大号码
                {
                    if (zdNum < Convert.ToInt32(strBall[j]))
                    {
                        zdNum = Convert.ToInt32(strBall[j]);//统计最大号码
                    }
                }
                if (m == "zx")//最小号码
                {

                    if (Convert.ToInt32(strBall[j]) < zxNum)
                    {
                        zxNum = Convert.ToInt32(strBall[j]);//统计最小号码
                    }
                }
                if (m == "jhjj")//跨度（最大号与最小号的差值）
                {
                    if (zdNum < Convert.ToInt32(strBall[j]))
                    {
                        zdNum = Convert.ToInt32(strBall[j]);//跨度（最大号与最小号的差值）--统计最大号码
                    }
                    if (Convert.ToInt32(strBall[j]) < zxNum)
                    {
                        zxNum = Convert.ToInt32(strBall[j]);////跨度（最大号与最小号的差值）--统计最小号码
                    }
                    jhjjZhi = zdNum - zxNum;
                }
                if (m == "zdjj")//最大邻间距（相邻两个红球号码之间的最大值）
                {
                    if (j == 0)
                    {
                        zdjjZhi = Math.Abs(Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j + 1]));
                        strZdjj = zdjjZhi + ",";
                    }
                    else
                    {
                        if (j <= strBall.Length - 2)
                        {
                            zdjjZhi = Math.Abs(Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j - 1]));
                            strZdjj += zdjjZhi + ",";
                            if (j == strBall.Length - 2)
                            {
                                string[] zdjjShuZu = strZdjj.Substring(0, strZdjj.Length - 1).Split(',');
                                for (int xx = 0; xx < zdjjShuZu.Length; xx++)
                                {
                                    if (zdNum < Convert.ToInt32(zdjjShuZu[xx]))
                                    {
                                        zdNum = Convert.ToInt32(zdjjShuZu[xx]);//统计最大邻间距号码
                                    }
                                }
                            }
                        }
                    }

                }
                if (m == "zxjj")//最小邻间距（相邻两个红球号码之间的最小值）
                {
                    if (j == 0)
                    {
                        zxjjZhi = Math.Abs(Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j + 1]));
                        strZdjj = zxjjZhi + ",";
                    }
                    else
                    {
                        if (j <= strBall.Length - 2)
                        {
                            zxjjZhi = Math.Abs(Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j - 1]));
                            strZdjj += zxjjZhi + ",";
                            if (j == strBall.Length - 2)
                            {
                                string[] zxjjShuZu = strZdjj.Substring(0, strZdjj.Length - 1).Split(',');
                                for (int xx = 0; xx < zxjjShuZu.Length; xx++)
                                {
                                    if (Convert.ToInt32(zxjjShuZu[xx]) < zxNum)
                                    {
                                        zxNum = Convert.ToInt32(zxjjShuZu[xx]);//统计最小邻间距号码
                                    }
                                }
                            }
                        }
                    }
                }
                if (m == "lh")//连号
                {
                    if (j > 0 && j < 6)
                    {
                        if (Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j - 1]) == 1)
                        {
                            lhCount++;
                        }
                    }
                }
                if (m == "lhz")//连号组数
                {
                    if (j > 0 && j < 6)
                    {
                        if (Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j - 1]) == 1)
                        {
                            lhzFlag++;
                        }
                        if (Convert.ToInt32(strBall[j]) - Convert.ToInt32(strBall[j - 1]) != 1 || j == 5)
                        {
                            if (lhzFlag != 0)
                            {
                                lhzFlag = 0;
                                lhzCount++;
                            }
                        }
                        if (lhzFlag == 5)
                        {
                            lhzFlag = 0;
                            lhzCount = 1;
                        }
                    }
                }
                if (m == "wsz")//尾数组数
                {
                    if (j == 0)
                    {
                        strWs = strBall[j].Substring(1, 1);
                    }
                    if (j > 0 && j < 6)//只计算红球
                    {
                        if (strWs.Contains(strBall[j].Substring(1, 1)))
                        {

                        }
                        else
                        {
                            wszCount++;
                            strWs += strBall[j].Substring(1, 1);
                        }
                        if (j == 5)
                        {
                            wszCount++;
                        }
                    }
                }
            }

            //------------------for外--------------------------
            if (m == "jh")//奇号个数
            {
                if (jhCount >= n && jhCount <= x) //如果满足过滤条件则接投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                jhCount = 0;
            }
            if (m == "dh")//大号个数
            {
                if (dhCount >= n && dhCount <= x) //如果满足过滤条件则接投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }

                dhCount = 0;
            }
            if (m == "hz")//号码和值
            {
                if (hzSum >= n && hzSum <= x) //如果满足过滤条件则接投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }

                hzSum = 0;
            }

            if (m == "zd")//最大号码
            {
                if (zdNum >= n && zdNum <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }

                zdNum = 0;
            }
            if (m == "zx")//最小号码
            {
                if (zxNum >= n && zxNum <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                zxNum = 34;
            }
            if (m == "jhjj")//跨度
            {
                if (jhjjZhi >= n && jhjjZhi <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                zdNum = 0;
                zxNum = 34;
                jhjjZhi = 0;
            }
            if (m == "zdjj")//最大邻间距
            {
                if (zdNum >= n && zdNum <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                zdNum = 0;
            }
            if (m == "zxjj")//最小邻间距
            {
                if (zxNum >= n && zxNum <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                zxNum = 34;
            }

            if (m == "lh")//连号个数
            {
                if (lhCount >= n && lhCount <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                lhCount = 0;
            }
            if (m == "lhz")//连号组数
            {
                if (lhzCount >= n && lhzCount <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                lhzCount = 0;
            }
            if (m == "wsz")//尾数组数
            {
                if (wszCount >= n && wszCount <= x) //如果满足过滤条件则将投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                {
                    //容错暂时不考虑//if (e == true)
                    newArray.Add(AllBall[i]);
                }
                wszCount = 0;
                strWs = "";
            }
        }
        BLL.ArrayListClass.SetArrayList(newArray);
        strBallsCount += newArray.Count.ToString() + ",";
        return newArray;
    }

    //-----------------------
    /// <summary>
    /// 【奇偶过滤——指标奇偶】过滤
    /// </summary>
    /// <param name="AllBall">自选号码后生成的号码</param>
    /// <param name="v">true 奇数 false 偶数</param>
    /// <param name="d">保留【False】/过滤【True】</param>
    /// <param name="e">e=false 不容错 e=true 容错</param>
    /// <param name="err_n">容错起始值</param>
    /// <param name="err_x">容错截止值</param>
    /// <param name="m">过滤描述 m=dh[大号个数]过滤</param>
    /// <param name="f">指标奇偶下的具体哪一项指标如号码和值，跨度等</param>
    /// <returns></returns>
    private ArrayList ZbJoFilter(ArrayList AllBall, string v, string d, bool e, int err_n, int err_x, string m, string f)
    {
        ArrayList newArray = new ArrayList();
        int hzSum = 0, zdNum = 0, zxNum = 34;//统计奇号个数
        for (int i = 0; i < AllBall.Count; i++)//循环生成的投注号码
        {
            //v中存的是true 奇数 false 偶数
            string[] strBall = AllBall[i].ToString().Split(',');//将每一注号码串中的‘，’分隔开，从而统计奇号个数
            for (int j = 0; j < strBall.Length - 1; j++) //包含红球，所以循环长度减1
            {
                if (f == "hz")//号码和值
                {
                    hzSum += Convert.ToInt32(strBall[j]);//统计号码和值
                }
                if (f == "zd")//最大号码
                {
                    if (hzSum < Convert.ToInt32(strBall[j]))
                    {
                        hzSum = Convert.ToInt32(strBall[j]);//统计最大号码
                    }
                }
                if (f == "zx")//最小号码
                {
                    if (Convert.ToInt32(strBall[j]) < zxNum)
                    {
                        zxNum = Convert.ToInt32(strBall[j]);//统计最小号码
                    }
                }
                if (f == "jhjj")//跨度（最大号与最小号的差值）
                {
                    if (zdNum < Convert.ToInt32(strBall[j]))
                    {
                        zdNum = Convert.ToInt32(strBall[j]);//跨度（最大号与最小号的差值）--统计最大号码
                    }
                    if (Convert.ToInt32(strBall[j]) < zxNum)
                    {
                        zxNum = Convert.ToInt32(strBall[j]);////跨度（最大号与最小号的差值）--统计最小号码
                    }
                    hzSum = zdNum - zxNum;
                }
                if (f == "whz") //尾号和值
                {
                    hzSum += Convert.ToInt32(strBall[j].Substring(1, 1));
                }
                if (f == "zxwh")//最小尾号
                {
                    if (Convert.ToInt32(strBall[j].Substring(1, 1)) < zxNum)
                    {
                        zxNum = Convert.ToInt32(strBall[j]);//统计最小号码
                    }
                }
                if (f == "zdwh")//最大尾号
                {
                    if (hzSum < Convert.ToInt32(strBall[j].Substring(1, 1)))
                    {
                        hzSum = Convert.ToInt32(strBall[j]);//统计最大号码
                    }
                }
                if (f == "yqhz")//一区和值
                {
                    if (Convert.ToInt32(strBall[j]) > 0 && Convert.ToInt32(strBall[j]) < 12)
                    {
                        hzSum += Convert.ToInt32(strBall[j].Substring(1, 1));
                    }
                }
                if (f == "eqhz")//二区和值
                {
                    if (Convert.ToInt32(strBall[j]) > 11 && Convert.ToInt32(strBall[j]) < 23)
                    {
                        hzSum += Convert.ToInt32(strBall[j].Substring(1, 1));
                    }
                }
                if (f == "sqhz")//三区和值
                {
                    if (Convert.ToInt32(strBall[j]) > 22 && Convert.ToInt32(strBall[j]) < 34)
                    {
                        hzSum += Convert.ToInt32(strBall[j].Substring(1, 1));
                    }
                }
                if (f == "hq1")//红球一
                {
                    hzSum = Convert.ToInt32(strBall[0]);
                }
                if (f == "hq2")//红球二
                {
                    hzSum = Convert.ToInt32(strBall[1]);
                }
                if (f == "hq3")//红球三
                {
                    hzSum = Convert.ToInt32(strBall[2]);
                }
                if (f == "hq4")//红球四
                {
                    hzSum = Convert.ToInt32(strBall[3]);
                }
                if (f == "hq5")//红球五
                {
                    hzSum = Convert.ToInt32(strBall[4]);
                }
                if (f == "hq6")//红球六
                {
                    hzSum = Convert.ToInt32(strBall[5]);
                }
                if (f == "lq1")//蓝球一
                {
                    hzSum = Convert.ToInt32(strBall[6]);
                }
            }
            //------------For 外----
            if (f == "zx" || f == "zxwh")
            {
                hzSum = zxNum;
            }
            if (d.ToLower() == "false") //保留
            {
                if (v.ToLower() == "true") //true为奇数
                {
                    if (hzSum % 2 != 0) //如果满足过滤条件则接投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                    {
                        //容错暂时不考虑//if (e == true)
                        newArray.Add(AllBall[i]);
                    }
                }
                else //false为偶数
                {
                    if (hzSum % 2 == 0) //如果满足过滤条件则接投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                    {
                        //容错暂时不考虑//if (e == true)
                        newArray.Add(AllBall[i]);
                    }
                }
            }
            else //过滤
            {
                if (v.ToLower() == "true") //true为奇数
                {
                    if (hzSum % 2 != 0) //如果满足过滤条件则接投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                    {
                        //容错暂时不考虑//if (e == true)
                    }
                    else
                    {

                        newArray.Add(AllBall[i]);
                    }
                }
                else //false为偶数
                {
                    if (hzSum % 2 == 0) //如果满足过滤条件则接投注串放到新的ArrayList里，以便直接取到过滤到的投注号
                    {
                        //容错暂时不考虑//if (e == true)
                    }
                    else
                    {
                        newArray.Add(AllBall[i]);
                    }
                }

            }

            hzSum = 0; zxNum = 34; zdNum = 0;

        }
        BLL.ArrayListClass.SetArrayList(newArray);
        strBallsCount += newArray.Count.ToString() + ",";
        return newArray;
    }
    //-------------
    /// <summary>
    /// 【奇偶/质合】过滤
    /// </summary>
    /// <param name="AllBall">自选号码后生成的号码</param>
    /// <param name="v"></param>
    /// <param name="d">保留【False】/过滤【True】</param>
    /// <param name="e">e=false 不容错 e=true 容错</param>
    /// <param name="err_n">容错起始值</param>
    /// <param name="err_x">容错截止值</param>
    /// <param name="m">过滤描述 m=dh[大号个数]过滤</param>
    /// <returns></returns>
    private ArrayList JoZhFilter(ArrayList AllBall, string v, string d, bool e, int err_n, int err_x, string m)
    {
        string strjoxt = "";//用来存奇偶形态选中号码中第几个数是偶数,【9,11,12,13,15,22,6】循环的下标值 如：strjoxt=0,1,5
                            //string strjoxtJs = ""; string strjoxtOs="";//用来存奇偶形态条件中第几个数是偶数,【1,1,2,1,1,2,2】循环的下标值 如：strjoxtJ=0,1,5
        ArrayList newArray = new ArrayList();
        string[] vArray = null; //过滤条件
        int PublicCount = 0;//公共变量存个数
        int osCount = 0;//oscount偶数个数，质合形态中应用
        string strTwzs = "";//尾号过滤--同尾组数，用来存每个号码的尾数
        string[] RedWsArray = null;//将每个尾数的值放入数组内，
        string temp = "";//临时变量--用来存储红球尾号中有【不相同】号码【尾号过滤--同尾组数与同尾尾数】
        string tempXT = "";//临时变量--用来存储红球尾号中有【相同】号码【尾号过滤--同尾组数与同尾尾数】
        for (int i = 0; i < AllBall.Count; i++)//循环生成的投注号码
        {
            //v中存的是1,1,2,2,1,1,2
            vArray = v.Split(',');//拆分串 1奇数  2为偶数【1,1,2,2,1,1,2】 
            string[] strBall = AllBall[i].ToString().Split(',');//将每一注号码串中的‘，’分隔开，从而统计奇号个数
            for (int j = 0; j < strBall.Length; j++)//包含红球与蓝球，所以循环长度减1
            {
                if (m == "twzs" || m == "twws")//同尾组数过滤 与同尾尾数
                {
                    if (j != strBall.Length - 1)//只计算红球，所以长度为Length-1
                    {
                        strTwzs += strBall[j].Substring(1, 1) + ",";
                    }
                }
                if (m == "dxbl")//大小比例(只包含红球)红球中大于等于17的数和小于17的数的比
                {
                    if (j != strBall.Length - 1)//只计算红球，所以长度为Length-1
                    {
                        if (Convert.ToInt32(strBall[j]) >= 17)//小于17为小数。大于等于17为大数
                        {
                            PublicCount++;//统计个数累加
                        }
                    }
                }
                if (m == "wdxxt")//尾号大小形态（红蓝球都包括）尾号0-4为小号，5-9为大号
                {
                    if (vArray[j].Trim() == "1")//小号
                    {
                        if (Convert.ToInt32(strBall[j].Substring(1, 1)) <= 4)
                        {
                            //PublicCount++;//尾号0-4为小号，这个变量加1
                        }
                        else
                        {
                            strjoxt = "error";
                        }
                    }
                    if (vArray[j].Trim() == "2")//大号
                    {
                        if (Convert.ToInt32(strBall[j].Substring(1, 1)) >= 5)
                        {
                            //osCount++;//5-9为大号，这个变量加1
                        }
                        else
                        {
                            strjoxt = "error";
                        }
                    }

                }

                if (m == "jobl")//奇偶比例(只包含红球)
                {
                    if (j != strBall.Length - 1)//只计算红球，所以长度为Length-1
                    {
                        if (Convert.ToInt32(strBall[j]) % 2 != 0)//不能被2整除的，则为奇数
                        {
                            PublicCount++;//统计奇数个数累加
                        }
                    }
                }
                if (m == "joxt")//奇偶形态（红蓝球都包括）
                {
                    if (vArray[j].Trim() == "1")
                    {
                        if (Convert.ToInt32(strBall[j]) % 2 != 0)
                        {
                        }
                        else
                        {
                            strjoxt = "error";
                        }
                    }
                    if (vArray[j].Trim() == "2")
                    {
                        if (Convert.ToInt32(strBall[j]) % 2 == 0)
                        {

                        }
                        else
                        {
                            strjoxt = "error";
                        }
                    }

                }
                if (m == "zhbl")//质合比例(只包含红球)
                {
                    if (j != strBall.Length - 1)//只计算红球，所以长度为Length-1
                    {
                        for (int xx = 2; xx < Convert.ToInt32(strBall[j]); xx++)
                        {
                            if (Convert.ToInt32(strBall[j]) % xx == 0)
                            {
                                PublicCount++;//能被整除则为合数，这个变量加1
                                break;
                            }
                        }
                    }
                }
                if (m == "zhxt")//质合形态（红蓝球都包括）
                {
                    if (vArray[j].Trim() == "1")
                    {
                        for (int xx = 2; xx < Convert.ToInt32(strBall[j]); xx++)
                        {
                            if (Convert.ToInt32(strBall[j]) % xx == 0)
                            {
                                PublicCount++;//能被整除则为合数，这个变量加1
                                break;
                            }
                        }
                        if (PublicCount != 0)
                        {
                            strjoxt = "error";
                        }
                        PublicCount = 0;
                    }
                    if (vArray[j].Trim() == "2")
                    {
                        for (int xx = 2; xx < Convert.ToInt32(strBall[j]); xx++)
                        {
                            if (Convert.ToInt32(strBall[j]) % xx == 0)
                            {
                                osCount++;//能被整除则为合数，这个变量加1
                                break;
                            }
                        }
                        if (osCount == 0)//偶数
                        {
                            strjoxt = "error";
                        }
                        osCount = 0;
                    }
                }
            }
            //------------For 外----
            if (m == "twws")//同尾尾数
            {
                //string Vrange = "";//设定尾数的，如果被勾选了，则为True
                temp = "";
                tempXT = "";
                RedWsArray = strTwzs.Substring(0, strTwzs.Length - 1).Split(',');//红球的尾数号码
                string CheckItemString = TrueConvertString(v);
                for (int cc = 0; cc < RedWsArray.Length; cc++)
                {
                    if (temp.Contains(RedWsArray[cc]))
                    {
                        tempXT += RedWsArray[cc] + ",";//投注号中的红球尾数，如果有相同的两位尾数，则记录至tempXT变量中
                        continue;                   //如果有重复就直接跳出本次循环
                    }
                    temp += RedWsArray[cc] + ",";
                }
                string[] WsArray = null;
                if (CheckItemString != null && CheckItemString != "")
                {
                    WsArray = CheckItemString.Substring(0, CheckItemString.Length - 1).Split(',');//已选中的尾数值
                }

                if (d.ToLower() == "false")
                {
                    for (int g = 0; g < WsArray.Length; g++)
                    {
                        if (tempXT.Contains(WsArray[g]))//将红球尾号出现重复的号与已选尾号，进行比较
                        {
                            newArray.Add(AllBall[i]);//如果包含abc中包含已选尾号，则添加至过滤结果中
                            strTwzs = "";
                            tempXT = "";
                            temp = "";
                            RedWsArray = null;
                            break; //当满足条件时，结束循环
                        }
                    }
                }
                else
                {
                    for (int g = 0; g < WsArray.Length; g++)
                    {
                        if (tempXT.Contains(WsArray[g]))//将红球尾号出现重复的号与已选尾号，进行比较
                        {
                            break;
                        }
                        if (g == WsArray.Length - 1)
                        {
                            newArray.Add(AllBall[i]);//如果包含abc中包含已选尾号，则添加至过滤结果中
                            strTwzs = "";
                            tempXT = "";
                            temp = "";
                            RedWsArray = null;
                        }

                    }
                }
                strTwzs = "";
                tempXT = "";
            }
            if (m == "twzs")//同尾组数
            {
                //string Vrange = "";
                RedWsArray = strTwzs.Substring(0, strTwzs.Length - 1).Split(',');//红球的尾数号码
                for (int cc = 0; cc < RedWsArray.Length; cc++)
                {
                    if (temp.Contains(RedWsArray[cc]))
                    {
                        if (tempXT.Contains(RedWsArray[cc]))
                        {

                        }
                        else
                        {
                            tempXT += RedWsArray[cc] + ",";//投注号中的红球尾数，如果有相同的两位尾数，则记录至tempXT变量中
                        }
                        continue;    //如果有重复就直接跳出本次循环
                    }
                    temp += RedWsArray[cc] + ",";
                }
                string CheckItemString = TrueConvertString(v);
                int tempXTcount = 0;
                if (tempXT != "")
                {
                    tempXTcount = tempXT.Substring(0, tempXT.Length - 1).Split(',').Length;
                }

                if (d.ToLower() == "false")//false为保留
                {
                    if (CheckItemString.Contains(tempXTcount.ToString()))
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                else//true为滤除
                {
                    if (CheckItemString.Contains(tempXTcount.ToString()))
                    {

                    }
                    else
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                tempXT = "";
                strTwzs = "";
                temp = "";
                RedWsArray = null;
            }
            if (m == "dxbl")//大小比例
            {
                //v中存的是true,false,false,false,false,false,false
                string CheckItemString = TrueConvertString(v);//拆分串 【0:6】,【1:5】,【2:4】,【3:3】,【4:2】,【5:1】,【6:0】 如果勾选则显示为true
                if (d.ToLower() == "false")//false为保留
                {
                    if (CheckItemString.Contains(PublicCount.ToString()))
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                if (d.ToLower() == "true")//true为滤除
                {
                    if (CheckItemString.Contains(PublicCount.ToString()))
                    {

                    }
                    else
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                PublicCount = 0;
            }

            if (m == "wdxxt")//尾号大小形态
            {
                if (d.ToLower() == "false")//保留为False
                {
                    if (strjoxt != "error")
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                else //滤除为True
                {
                    if (strjoxt == "error")
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                strjoxt = "";
            }
            if (m == "zhbl")//质合比例
            {
                string CheckItemString = TrueConvertString(v);
                if (d.ToLower() == "false")//false为保留
                {
                    if (CheckItemString.Contains(Convert.ToInt32(6 - PublicCount).ToString()))
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                if (d.ToLower() == "true")//true为滤除
                {
                    if (CheckItemString.Contains(Convert.ToInt32(6 - PublicCount).ToString()))
                    {

                    }
                    else
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                PublicCount = 0;
            }

            if (m == "zhxt")//质合形态
            {
                if (d.ToLower() == "false")//保留为False
                {
                    if (strjoxt != "error")
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                else //滤除为True
                {
                    if (strjoxt == "error")
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                strjoxt = "";

            }

            if (m == "jobl")
            {
                string CheckItemString = TrueConvertString(v);
                if (d.ToLower() == "false")//false为保留
                {
                    if (CheckItemString.Contains(PublicCount.ToString()))
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                if (d.ToLower() == "true")//true为滤除
                {
                    if (CheckItemString.Contains(PublicCount.ToString()))
                    {

                    }
                    else
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                PublicCount = 0;
            }

            if (m == "joxt")//奇偶形态
            {
                if (d.ToLower() == "false")//保留为False
                {
                    if (strjoxt != "error")
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                else //滤除为True
                {
                    if (strjoxt == "error")
                    {
                        newArray.Add(AllBall[i]);
                    }
                }
                strjoxt = "";

            }
        }
        BLL.ArrayListClass.SetArrayList(newArray);
        strBallsCount += newArray.Count.ToString() + ",";
        return newArray;

    }

    //------------------------------------------------------------------------------------
    string CheckItem = "";
    //拆分串"false,false,true,true,false,false,false" 次数为0,1,2,3,4,5,6
    public string TrueConvertString(string h)
    {

        CheckItem = "";
        string[] hArray = h.Split(',');
        for (int i = 0; i < hArray.Length; i++)
        {
            if (hArray[i].Trim().ToLower() == "true")
            {
                CheckItem += i + ",";
            }
        }
        return CheckItem;
    }
    //----------------------------------------------------------------------------------
    //向数据库中增加记录【在线过滤表】
    private void newarrayByTogether_Zxgl()
    {
        //if (loginUserInfo == null)
        //{
        //    alertmessageAndGo("请先登录！", "/Default.aspx");
        //    return;
        //}
        //else
        //{

        //if (loginUserInfo.Id > 0 && loginUserInfo.userLevel == 2)//需要测试会员
        //{
        try
        {
            Model.CMember loginUserInfo = BLL.CMember.UserLoginInfo();

            Model.UsersAccount userAccout = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
            //Model.UsersAccount userAccout = BLL.UsersAccount.GetModelByuser_id(18);
            int type = ReadRequest.RequestInt("type");//彩种类型 tpye=1 双色球
            int fctype = ReadRequest.RequestInt("fctype");//针对福彩3D 使用 1:直选, 2:通选,3:组三,4:组六,5:和数,6:包选，7:1D，8:2D,9:大小奇偶,10:拖拉机，11:猜三同 
            int lotteryPlay = 0;
            int mymoney = ReadRequest.RequestInt("MySub");//我要认购
            int mybd = ReadRequest.RequestInt("MyGua");//我要保底
                                                       //string LotteryNo=ReadRequest.RequestString("redBall")+"+"+ReadRequest.RequestString("blueBall");//号码
            ArrayList LotteryArrayList = BLL.ArrayListClass.GetArrayList();//号码
            string[] strball = (string[])LotteryArrayList.ToArray(typeof(string));

            for (int i = 0; i < strball.Length; i++)
            {
                strball[i] = strball[i].Substring(0, strball[i].LastIndexOf(',')).Replace(",", "*") + strball[i].Substring(strball[i].LastIndexOf(',')).Replace(",", "+");
            }
            string LotteryNo = string.Join(",", strball);
            string LotterReplace = LotteryNo.Replace(",", "*");
            Model.LotteryChipped_Zxgl model = new Model.LotteryChipped_Zxgl();
            model.UserID = Convert.ToInt32(loginUserInfo.Id);
            model.LotteryType = type;
            model.LotteryOpenTime = ReadRequest.RequestString("qs");
            model.LotteryMultiple = ReadRequest.RequestInt("beishu");//投几倍
            model.LotteryCount = ReadRequest.RequestInt("oldCount");//个数
            model.LotteryAfterCount = ReadRequest.RequestInt("newCount");//过滤后新个数
                                                                         //model.LotteryNo = LotteryNo.Replace(',', '*');
            model.LotteryNo = LotteryNo;
            model.LotteryMoney = model.LotteryCount * 2 * model.LotteryMultiple;//投注的钱数
            model.LotteryAfterMoney = model.LotteryAfterCount * 2 * model.LotteryMultiple;//过滤投注的钱数
            model.LotteryZip = ReadRequest.RequestString("lotteryZip");//压缩比
            model.Name = ReadRequest.RequestString("fabt");//方案标题
            model.Describe = ReadRequest.RequestString("hmxy");//合买宣言
            model.Commission = ReadRequest.RequestString("hm_ticheng");//盈利提成百分比
            if (mymoney < Math.Round(double.Parse(model.LotteryMoney.ToString()) * 0.05))
            {
                mymoney = (int)Math.Round(double.Parse(model.LotteryMoney.ToString()) * 0.05);//如果小于认购的百分之5，则按百分之5计算
            }
            if (mymoney > int.Parse(model.LotteryMoney.ToString()))
            {
                mymoney = int.Parse(model.LotteryMoney.ToString());
            }
            if (mybd < 0)
            {
                mybd = 0;//如果保底金额小于，则保底金额=0
            }
            if (mybd > (int.Parse(model.LotteryMoney.ToString()) - mymoney))
            {
                mybd = int.Parse(model.LotteryMoney.ToString()) - mymoney;//如果保底的钱数大于总钱数-认购的钱数，则保底金额=总钱数-认购的钱数
            }
            model.MySub = mymoney;//我要认购
            model.MyGua = mybd;//我要保底
            model.LotteryPlay = lotteryPlay;//玩法0单式 1复式 2 "全复式" 3胆拖   
            model.LotteryWinMoney = 0;//盈利佣金
            model.LotteryJD = 0;//进度
            model.LotteryYE = int.Parse(model.LotteryMoney.ToString()) - mymoney;//剩余金额
            model.State = false;//状态是否已满

            model.IsWin = false;//是否中奖
            model.WinLevel = -1;//中奖等级
            model.WinMoney = 0;//奖金
            model.AddTime = DateTime.Now;
            model.Flag = false;//是否过期：0还未派奖；1已派奖
            model.fcType = fctype;//针对福彩3D 使用 1:直选, 2:通选,3:组三,4:组六,5:和数,6:包选，7:1D，8:2D,9:大小奇偶,10:拖拉机，11:猜三同 
            model.IsOpen = ReadRequest.RequestInt("gongkai"); //是否1公开，2.销售截止后公开，3.仅对认购用户公开
            model.secret = Cryptogram.MD5(Cryptogram.SHA256Encrypt(model.LotteryNo + "-" + model.AddTime));//Cryptogram.MD5(Cryptogram.SHA256Encrypt(model.LotteryNo + "-" + model.AddTime))的加密字符
            if (model.LotteryMoney > userAccout.total)
            {
                alertmessageAndGo("您的账户余额不足请充值！", "/per_will_deposit.aspx?p=1");
                return;
            }
            else
            {
                try
                {
                    long createid = BLL.LotteryChipped_Zxgl.Add(model);

                    if (createid > 0)
                    {
                        //alertmessageAndGo("投注成功！", "/per_together.aspx?n=5&StrClear=" + type);
                     
                        HttpContext.Current.Response.Redirect("/TouZhuZhan.aspx?n=5&StrClear=" + type);
                        return;

                    }
                    else
                    {
                        alertmessageAndGoback("投注失败！");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    HttpContext.Current.Response.Write(ex.ToString());
                }
            }
        }
        catch
        {
            alertmessageAndGoback("数据不正确，请重新输入！");
            return;
        }

        //}
        //else
        //{

        //    alertmessageAndGoback("您必须是测试会员才可以投注！");
        //    return;
        //}
        //}
    }
    //-----------------------------------------------------------------------------------------------
    //向数据库中增加记录【合买表】
    private void newarrayByTogether()
    {
        //if (loginUserInfo == null)
        //{
        //    alertmessageAndGo("请先登录！", "/Default.aspx");
        //    return;
        //}
        //else
        //{

        //if (loginUserInfo.Id > 0 && loginUserInfo.userLevel == 2)//需要测试会员
        //{
        try
        {
            Model.CMember loginUserInfo = BLL.CMember.UserLoginInfo();

            Model.UsersAccount userAccout = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
            //Model.UsersAccount userAccout = BLL.UsersAccount.GetModelByuser_id(18);
            int type = ReadRequest.RequestInt("type");//彩种类型 tpye=1 双色球
            int fctype = ReadRequest.RequestInt("fctype");//针对福彩3D 使用 1:直选, 2:通选,3:组三,4:组六,5:和数,6:包选，7:1D，8:2D,9:大小奇偶,10:拖拉机，11:猜三同 
            int lotteryPlay = 0;
            int mymoney = ReadRequest.RequestInt("MySub");//我要认购
            int mybd = ReadRequest.RequestInt("MyGua");//我要保底
                                                       //string LotteryNo=ReadRequest.RequestString("redBall")+"+"+ReadRequest.RequestString("blueBall");//红球和蓝球号码
            ArrayList LotteryArrayList = BLL.ArrayListClass.GetArrayList();//号码
            string[] strball = (string[])LotteryArrayList.ToArray(typeof(string));

            for (int i = 0; i < strball.Length; i++)
            {
                strball[i] = strball[i].Substring(0, strball[i].LastIndexOf(',')).Replace(",", "*") + strball[i].Substring(strball[i].LastIndexOf(',')).Replace(",", "+");
            }
            string LotteryNo = string.Join(",", strball);
            string LotterReplace = LotteryNo.Replace(",", "*");
            Model.LotteryChipped model = new Model.LotteryChipped();
            model.UserID = Convert.ToInt32(loginUserInfo.Id);
            model.LotteryType = type;
            model.LotteryOpenTime = ReadRequest.RequestString("qs");
            model.LotteryMultiple = ReadRequest.RequestInt("beishu");//投几倍
            model.LotteryCount = ReadRequest.RequestInt("oldCount");//个数
                                                                    //model.LotteryNo = LotteryNo.Replace(',', '*');
            model.LotteryNo = LotteryNo;
            model.LotteryMoney = model.LotteryCount * 2 * model.LotteryMultiple;//投注的钱数
            model.Name = ReadRequest.RequestString("fabt");//方案标题
            model.Describe = ReadRequest.RequestString("hmxy");//合买宣言
            model.Commission = ReadRequest.RequestString("hm_ticheng");//盈利提成百分比
            if (mymoney < Math.Round(double.Parse(model.LotteryMoney.ToString()) * 0.05))
            {
                mymoney = (int)Math.Round(double.Parse(model.LotteryMoney.ToString()) * 0.05);//如果小于认购的百分之5，则按百分之5计算
            }
            if (mymoney > int.Parse(model.LotteryMoney.ToString()))
            {
                mymoney = int.Parse(model.LotteryMoney.ToString());
            }
            if (mybd < 0)
            {
                mybd = 0;//如果保底金额小于，则保底金额=0
            }
            if (mybd > (int.Parse(model.LotteryMoney.ToString()) - mymoney))
            {
                mybd = int.Parse(model.LotteryMoney.ToString()) - mymoney;//如果保底的钱数大于总钱数-认购的钱数，则保底金额=总钱数-认购的钱数
            }
            model.MySub = mymoney;//我要认购
            model.MyGua = mybd;//我要保底
            model.LotteryPlay = lotteryPlay;//玩法0单式 1复式 2 "全复式" 3胆拖   
            model.LotteryWinMoney = 0;//盈利佣金
            model.LotteryJD = 0;//进度
            model.LotteryYE = int.Parse(model.LotteryMoney.ToString()) - mymoney;//剩余金额
            model.State = false;//状态是否已满

            model.IsWin = false;//是否中奖
            model.WinLevel = -1;//中奖等级
            model.WinMoney = 0;//奖金
            model.AddTime = DateTime.Now;
            model.Flag = false;//是否过期：0还未派奖；1已派奖
            model.fcType = fctype;//针对福彩3D 使用 1:直选, 2:通选,3:组三,4:组六,5:和数,6:包选，7:1D，8:2D,9:大小奇偶,10:拖拉机，11:猜三同 
            model.IsOpen = ReadRequest.RequestInt("gongkai"); //是否1公开，2.销售截止后公开，3.仅对认购用户公开
            model.secret = Cryptogram.MD5(Cryptogram.SHA256Encrypt(model.LotteryNo + "-" + model.AddTime));//Cryptogram.MD5(Cryptogram.SHA256Encrypt(model.LotteryNo + "-" + model.AddTime))的加密字符
            if (model.LotteryMoney > userAccout.total)
            {
                //alertmessageAndGo("您的账户余额不足请充值！", "/recharge.aspx?flag=3");
                alertmessageAndGo("您的账户余额不足请充值！", "/per_will_deposit.aspx?p=1");
                return;
            }
            else
            {
                long createid = BLL.LotteryChipped.Add(model);
                if (createid > 0)
                {
                    decimal goldNum = 0;
                    decimal moneyNum = 0;
                    if (model.LotteryMoney > userAccout.goldTotal)//金币不足，需扣一部分现金
                    {
                        decimal plus = model.LotteryMoney - userAccout.goldTotal;
                        goldNum = model.LotteryMoney;
                        moneyNum = plus;
                        userAccout.goldTotal = 0;
                        userAccout.total = userAccout.total - plus;

                    }
                    else//金币充足，全部从金币中扣
                    {
                        userAccout.goldTotal = userAccout.goldTotal - model.LotteryMoney;
                        userAccout.total = userAccout.total;
                        goldNum = model.LotteryMoney;
                        moneyNum = 0;
                    }
                    //userAccout.total = userAccout.total - model.LotteryMoney;
                    userAccout.buyLotteryTotal = userAccout.buyLotteryTotal + model.LotteryMoney;
                    if (BLL.UsersAccount.Update(userAccout) > 0)
                    {
                        Model.LotteryBuyCost_temp Cost_temp = new Model.LotteryBuyCost_temp();
                        Cost_temp.user_id = int.Parse(loginUserInfo.Id.ToString());

                        Cost_temp.LotteryChippedid = createid;
                        Cost_temp.GoldCode = goldNum;
                        Cost_temp.Money = moneyNum;
                        Cost_temp.AddTime = System.DateTime.Now;
                        Cost_temp.LotteryChipperFrom = 1;
                        BLL.LotteryBuyCost_temp.Add(Cost_temp);//记录本次购买消耗了多少金币，多少钱
                        this.InsertIngratel(userAccout.user_id, 1, "购买彩票获得" + model.LotteryMoney + "分", model.LotteryMoney);
                        //alertmessageAndGo("投注成功！", "/per_together.aspx?n=5&StrClear=" + type);
                        newarrayByTogether_Zxgl();//调用在线过滤方法
                        return;
                    }
                }
                else
                {
                    alertmessageAndGoback("投注失败！");
                    return;
                }
            }
        }

        catch
        {
            alertmessageAndGoback("数据不正确，请重新输入！");
            return;
        }

        //}
        //    else
        //    {

        //        alertmessageAndGoback("您必须是测试会员才可以投注！");
        //        return;
        //    }
        //}
    }
    /// <summary>
    /// 添加积分获得使用信息表
    /// </summary>
    /// <param name="userid">用户id</param>
    /// <param name="type">1.获得，2消费</param>
    /// <param name="content">使用说明</param>
    /// <param name="userIntegral">使用积分数</param>
    private void InsertIngratel(long userid, int type, string content, decimal userIntegral)
    {
        Model.IntegralExchange Ingratel = new Model.IntegralExchange();
        Ingratel.Type = type;
        Ingratel.UseIntegral = userIntegral;
        Ingratel.OrderId = DateTime.Now.ToString("yyyyMMddhhmmss");
        Ingratel.Addtime = DateTime.Now;
        Ingratel.Content = content;
        Ingratel.IsSuccess = true;
        Ingratel.UserId = userid;
        BLL.IntegralExchange.Add(Ingratel);
    }
}